package com.zhongxi.guoyuan.adapter.seller;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/1/23.
 */

public class SellerMallWithDrawAdapter extends RecyclerView.Adapter<SellerMallWithDrawAdapter.MyViewHolder> {

    private Context context;
    private List<SellerMallWithDrawResult.ListData> list;
    private SellerMallWithDrawResult.ListData listData;

    public SellerMallWithDrawAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    public void setList(List<SellerMallWithDrawResult.ListData> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view= LayoutInflater.from(context).inflate(R.layout.with_draw_recode,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if(null!=list&&!"".equals(list)){
            listData = list.get(position);
            if(null!=listData.getApply_ctime()&&!"".equals(listData.getApply_ctime())){
                holder.mallWithdrawTime.setText(listData.getApply_ctime());
            }else{
                holder.mallWithdrawTime.setText("");
            }
            if(null!=listData.getAmount()&&!"".equals(listData.getAmount())){
                holder.mallWithdrawNumber.setText(listData.getAmount());
            }else{
                holder.mallWithdrawNumber.setText("");
            }

            if(null!=listData.getStatus()&&!"".equals(listData.getStatus())){
                if (listData.getStatus().equals("0")){//未发放
                    holder.mallWithdrawStatus.setText("受理中");
                    holder.mallWithdrawStatus.setTextColor(context.getResources().getColor(R.color.red));
                    holder.mallWithdrawPoint.setVisibility(View.VISIBLE);
                }else {
                    holder.mallWithdrawStatus.setText("已兑现");
                    holder.mallWithdrawStatus.setTextColor(context.getResources().getColor(R.color.bg_yield));
                    holder.mallWithdrawPoint.setVisibility(View.INVISIBLE);
                }
            }
        }
    }

    @Override
    public int getItemCount() {
        return list!=null?list.size():0;
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.mall_withdraw_time)
        TextView mallWithdrawTime;
        @Bind(R.id.mall_withdraw_number)
        TextView mallWithdrawNumber;
        @Bind(R.id.mall_withdraw_status)
        TextView mallWithdrawStatus;
        @Bind(R.id.mall_withdraw_point)
        ImageView mallWithdrawPoint;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this,view);
        }
    }
}
